﻿$(function () {

    var eid=get_url_id();

    var app = new Vue({
                el: '#app_vue',
                data: {
                    vm:{},
                    id:eid,
                },
                methods: {
                    appointment: function (id) {
                        //判断是否登录
                        is_login();
                        //页面跳转
                        location.href = 'tj_indent.html?'+ id;
                    }
                }
    });

    if(eid>0)
    {
        $.ajax({
                    url: '/Api/tj_list_details_show',
                    type: 'post',
                    data: { id: eid },
                    dataType: 'json',
                    success: function (data) {
                        if(data.Code==1)
                        {
                            app.vm=data.Data;
                            app.vm.hospital_name=data.Data.Hospital.Name;
                        }
                    }
                });
    }

    //套餐详情
    //$.ajax({
    //    url: '/Api/tj_list_details_show',
    //    type: 'post',
    //    data: { id: eid },
    //    dataType: 'json',
    //    success: function (data) {
    //        $("#tj_content").empty();
    //        $("#appropriate_div").empty();
    //        $("#app_check").empty();

    //        var tj_content = "<h3>" + data.Name
    //        + "</h3><p class=\"tc_info_p\">"
    //        + data.Details
    //        + "</p><div class=\"tc_picbox\"><span class=\"pic\"> <i>￥</i>"
    //        + data.Price
    //        + "</span> <del>原价："
    //        + data.Oldprice
    //        + "</del><a class=\"btn\" id=\"tao\" onclick=\"IsLogin()\" href=\"#\">立即预约</a></div><div class=\"pay_box\"><span class=\"online\">在线付</span><span class=\"shuliang\">"
    //        + data.Sonnum + "人预约</span></div><div class=\"chennbox\"><span class=\"th_icon\">退货承诺</span><span class=\"yysc_icon\">医院授权</span></div>";

    //        var appropriate = "<a href=\"javascript:;\">" + data.Appropriate + "</a>";
    //        var check = "" + data.Scheck + "";
    //        $("#tj_content").append(tj_content);
    //        $("#appropriate_div").append(appropriate);
    //        $("#app_check").append(check);

    //    }
    //});

    //$.ajax({
    //    url: '/MVC/tj_list_details_show',
    //    type: 'post',
    //    data: { id: eid },
    //    dataType: 'json',
    //    success: function (d1) {
    //        $("#tab").empty();

    //        $(d1).each(function (i, obj) {
    //            var accordion = ' <tr> <td width="100"><span class="rq_label">' + obj.Name + '</span></td> <td><p>' + obj.Purpose + '</p></td></tr>';
    //            $("#tab").append(accordion);
    //        })
    //    }
    //});
});

//判断是否登录
function is_login() {
    $.ajax({
        url: '/Api/IsLogin',
        type: 'post',
        dataType: 'json',
        success: function (data) {
            if (data.Code != 1) {
                //直接跳转到登录
                location.href = '/wap/login.html';
                return;
            }
            //else {
            //    //填写订单
            //    location.href = "/wap/tj_indent.html?" + eid;
            //    return;
            //}
        },
        beforeSend: function (xhr) {
            var storage = window.localStorage;
            var ticket = storage.getItem('token');
            xhr.setRequestHeader("token", ticket);
        }
    });
}